package com.jin.webvideo.base.linkedfile.io;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class RandomAccessVFile extends RandomAccessFile {
    private long offset;

    public RandomAccessVFile(String name, String mode) throws FileNotFoundException {
        super(name, mode);
    }

    public RandomAccessVFile(File file, String mode) throws FileNotFoundException {
        super(file, mode);
    }

    public void store() throws IOException {
        this.offset = getFilePointer();
    }

    public void reStore() throws IOException {
        seek(this.offset);
    }

    /**
     * 读取无符号int
     * @return
     * @throws IOException
     */
    public long readUnsignedInt() throws IOException {
        return Integer.toUnsignedLong(readInt());
    }

    public String readUTFBlockByUnsignedShort() throws IOException {
        int len = this.readUnsignedShort();
        byte[] bs = new byte[len];
        this.read(bs);
        return new String(bs, 0, len, StandardCharsets.UTF_8);
    }
}
